<template>
  <div class="popup flex-center flex-align-items-center">
    <div class="main">
      <div class="main-header">
        <p>修改收藏夹</p>
        <i class="iconfont icon-guanbi" @click="close"></i>
      </div>
      <el-form ref="ruleFormRef" :model="form" :rules="rules" label-position="top" class="rule-form">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" type="text" maxlength="60" />
        </el-form-item>
        <el-form-item label="描述" prop="desc">
          <el-input v-model="form.desc" type="textarea" maxlength="150" />
        </el-form-item>
        <el-form-item>
          <div class="form-open flex-between flex-align-items-center">
            <p class="form-open-label font-14">团队公开</p>
            <el-switch />
          </div>
        </el-form-item>
        <div class="btns flex">
          <p class="font-14 pointer" @click="close">取消</p>
          <p class="font-14 pointer" @click="submitForm(ruleFormRef)">确定</p>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits, ref } from 'vue';
const props = defineProps(['info']);
const emit = defineEmits(['close']);

const rules = {
  name: [
    { required: true, message: '请输入推广计划名称', trigger: 'blur' },
    { min: 3, max: 60, message: '长度在 3 到 60 个字符', trigger: 'blur' },
  ],
  desc: [
    { min: 3, max: 150, message: '长度在 3 到 150 个字符', trigger: 'blur' },
  ]
};

const form = ref(props.info);
const ruleFormRef = ref();

const close = () => {
  emit('close', null);
}
const submitForm = async formEl => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
      emit('close', {
        name: form.value.name,
        desc: form.value.desc
      });
    } else {
      console.log('error submit!', fields)
    }
  })
}
</script>

<style lang="less" scoped>
.popup {
  .main {
    position: relative;
    width: 390px;
    border-radius: 10px;
    background: #fff;

    .rule-form {
      padding: 16px 24px;

      &::v-deep {
        .el-form-item__content {
          margin-bottom: 18px;
        }

        input {
          height: 32px;
        }

        textarea {
          height: 90px;
        }
      }

      .form-open {
        width: 100%;

        .form-open-label {
          color: #333;
        }
      }

      .btns {
        justify-content: end;
        margin-top: 25px;

        p {
          transition: .1s;
          padding: 10px 20px;
          border-radius: 4px;

          &:last-child {
            color: #fff;
            background-color: #ff5277;
            border-color: #ff5277;
            margin-left: 10px;

            &:hover {
              background: #ff7592;
              border-color: #ff7592;
              color: #fff;
            }
          }

          &:first-child {
            border: 1px solid #dcdfe6;
            color: #606266;

            &:hover {
              color: @main-color;
              border-color: #ffcbd6;
              background-color: #ffeef1;
            }
          }
        }
      }
    }
  }
}
</style>
